package com.faradel.pharmapp.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.faradel.pharmapp.entities.Medication;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.faradel.pharmapp.dao.MedicationDAO;

@Repository("medicationServiceImpl")
public class MedicationServiceImpl implements MedicationServiceInterface
{
    @Resource
    MedicationDAO medicationDaoImpl;

    @Override
    @Transactional(readOnly = false)
    public void addMedication(Medication medication)
    {
        medicationDaoImpl.save(medication);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateMedication(Medication medication)
    {
        medicationDaoImpl.update(medication);
    }

    @Override
    @Transactional(readOnly = false)
    public void deleteMedication(Medication medication)
    {
        medicationDaoImpl.delete(medication);
    }

    @Override
    @Transactional(readOnly = true)
    public Medication getMedicationById(int id)
    {
        return medicationDaoImpl.get(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Medication> getAllMedications()
    {
        return medicationDaoImpl.selectAll();
    }

    @Override
    @Transactional(readOnly = true)
    public List<Medication> getMedicationByColumns(Map<String, String> map)
    {
        return medicationDaoImpl.findByColumn(map);
    }

}
